package com.info.zhiduoduo.repository.mapper.system;

import com.baomidou.mybatisplus.mapper.BaseMapper;
import com.info.zhiduoduo.repository.dto.system.RoleMenuDto;
import com.info.zhiduoduo.repository.entity.system.SystemRoleMenu;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

public interface RoleMenuMapper extends BaseMapper<SystemRoleMenu> {


    /**
     * 添加角色菜单
     * @param roleid
     * @param menuIdStr
     * @return
     */
    @Insert("<script>" +
            "insert into zdd_system_rolemenu (roleid,menuid) values " +
            "<foreach collection =\"menuIdStr\" item=\"item\" index=\"index\" separator =\",\">" +
            "(#{roleid},#{item}) " +
            "</foreach>" +
            "</script> ")
    int saveRoleMenu(@Param("roleid") int roleid, @Param("menuIdStr") String[] menuIdStr);

    /**
     * 删除角色绑定的菜单
     * @param roleid
     * @return
     */
    @Delete("delete from zdd_system_rolemenu where roleid = #{roleid}")
    int deleteSystemRoleMenu(@Param("roleid") int roleid);

    @Select(" select m.menuid,m.menuname,m.menuvalue " +
            " from zdd_system_rolemenu rm " +
            " join zdd_system_menu m on m.menuid = rm.menuid " +
            " where rm.roleid = #{roleid}")
    List<RoleMenuDto> getRoleMenuList(@Param("roleid") int roleid);
}
